﻿using AutoMapper;
using commodity.Dtos;
using commodity.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace commodity.Profiles
{
    public class CommodityProflie:Profile
    {

        public CommodityProflie()
        {
           
            CreateMap<FirstsCommodityMenu, FirstsCommdityMenuDto>();
            CreateMap<SecondCommodityMenu, SecondCommdityMenuDto>();
            CreateMap<SecondCommodityMenuCommodity, SecondCommodityMenuCommodityDto>();
            CreateMap<Commodity, CommodityDto>();
            CreateMap<CommodityInformation, CommodityInformationDto>()
                .ForMember(
                desp => desp.state,
                opt => opt.MapFrom(src => (int)src.state)
                ).ForMember(
                desp => desp.Value,
                opt => opt.MapFrom(
                    src => src.GetString(src.Value)
                    )
                ) ;
            CreateMap<CommodityInformationDto, CommodityInformation>()
                .ForMember(
                desp => desp.state,
                opt => opt.MapFrom(src => (StateProperty)src.state)
                ).ForMember(
                desp=>desp.Value,
                opt=>opt.MapFrom(src=>string.Join(",",src.Value))
                );
            CreateMap<CommodityInformation, GetCommodityDto>()
                .ForMember(
                desp => desp.Attr_Id,
                opt => opt.MapFrom(src => src.commodity.id)
                ).ForMember(
                desp => desp.Attr_Name,
                opt => opt.MapFrom(src => src.commodity.CommodityName)
                ).ForMember(
                desp => desp.Attr_Sel,
                opt => opt.MapFrom(src =>src.state)
                ).ForMember(
                desp => desp.Attr_Write,
                opt => opt.MapFrom(src =>src.PropertyName)
                ).ForMember(
                desp => desp.Attr_Vals,
                opt => opt.MapFrom(src=>src.GetString(src.Value))
                ).ForMember(
                desp=>desp.Cat_Id,
                opt=>opt.MapFrom(src=>src.id)
                );
            CreateMap<GetCommodityDto, CommodityInformation>()
                .ForMember(
                desp => desp.id,
                opt => opt.MapFrom(src => src.Cat_Id)
                ).ForMember(
                desp => desp.state,
                opt => opt.MapFrom(src => src.Attr_Sel)
                ).ForMember(
                desp => desp.CommodityId,
                opt => opt.MapFrom(src => src.Attr_Id)
                ).ForMember(
                desp => desp.PropertyName,
                opt => opt.MapFrom(src => src.Attr_Write)
                ).ForMember(
                desp => desp.Value,
                opt => opt.MapFrom(src => string.Join(",", src.Attr_Vals))
                );
        }
    }
}
